package com.hsj.mqconsumer.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import pojo.User;

import java.io.IOException;
import java.util.Map;

/**
 * @author:Teacher黄
 * @date:Created at 2020/01/04
 */
@Component
public class ObjectConsumer {



    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "object_queue",durable = "true",autoDelete = "false"),
            exchange = @Exchange(name = "hsj_exchange"),
            key = "object_route"
    ))
    public void consumeObject(@Payload User user, @Headers Map<String,Object> headers, Channel channel) throws IOException {
        System.out.println("接收到:"+user);
        long deliverTag = (long) headers.get(AmqpHeaders.DELIVERY_TAG);
        channel.basicAck(deliverTag,true);
    }


}
